<?php
namespace app\backstage\logic;
use think\Db;
class Faq
{
    /*列表数据获取*/
    public function getList($params)
    {
        $field = 'id,uid,content,type,from_id,reply_account_id,have_read,user_reply_time,create_time';
        $condition[] = ['uid','eq','egt:0','uid'];
        $condition[] = ['have_read','eq','egt:0','have_read'];
        $condition[] = ['quick_id','eq','gt:0','quick_id'];
        $condition[] = ['from_id','eq','gt:0','from_id'];
        $condition[] = ['type', 'eq', 'require','type'];
        $condition[] = ['advert_account', 'like', 'require','advert_account'];
        $where   = buildQueryCondition($condition, $params);

        if( isset($params['field']) ){
            $orderBy = [ $params['field'] => $params['order'] ];
        }else{
            $orderBy = ['user_reply_time' => 'desc', 'id' => 'desc'];
        }
        $Faq = \think\facade\App::model('Faq');
        $list = $Faq->getList($where, $field, $params['page'], $params['limit'], $orderBy);

        $result['count']    = $Faq->getTotalNumber($where);
        $result['list']     = $list;
        return $result;
    }

    /*数据获取*/
    public function getInfo($where)
    {
        $field = 'id,uid,content,type,from_id,reply_account_id,create_time';
        $Faq = \think\facade\App::model('Faq');
        $info = $Faq->getOne($where,$field);
        return $info;
    }

    /*数据添加*/
    public function addInfo($data)
    {
        $Faq = \think\facade\App::model('Faq');
        $res = $Faq->insertRecord($data);
        return $res;
    }

}